package gemini.pollux.ui.client.page.content.product.producttype;

import com.google.gwt.event.shared.GwtEvent;

public class ProductTypeEvent extends GwtEvent<ProductTypeHandler> {

	private static Type<ProductTypeHandler> TYPE;
	
	public static Type<ProductTypeHandler> getType() {
		if (TYPE == null)
			TYPE = new Type<ProductTypeHandler>();
		return TYPE;
	}
	
	public enum ForwardType {
		EDIT, NEW, BACK_TO_LIST;
	}
	
	public ProductTypeEvent(ForwardType forwardType) {
		super();
		this.setForwardType(forwardType);
	}
	
	private ForwardType forwardType;

	@Override
	protected void dispatch(ProductTypeHandler handler) {
		if (forwardType.equals(ForwardType.EDIT)) {
			handler.onEdit(this);
		} else if (forwardType.equals(ForwardType.NEW)) {
			handler.onNew(this);
		}  else if (forwardType.equals(ForwardType.BACK_TO_LIST)) {
			handler.onBackToList(this);
		} 
	}

	@Override
	public Type<ProductTypeHandler> getAssociatedType() {
		return getType();
	}

	public void setForwardType(ForwardType forwardType) {
		this.forwardType = forwardType;
	}

	public ForwardType getForwardType() {
		return forwardType;
	}
}
